using System.Text;

namespace OpenWaves.Text
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "ASCII")]
    public class BestFitASCIIEncoding : ASCIIEncoding
    {
        private static readonly Encoding instance = CreateInstance();

        private static Encoding CreateInstance()
        {
            var encoding = (Encoding) Encoding.ASCII.Clone();
            encoding.EncoderFallback = new BestFitASCIIEncoderFallback();

            return encoding;
        }

        public static Encoding Instance
        {
            get { return instance; }
        }

        public static string Encode(string input)
        {
            return Instance.GetString(Instance.GetBytes(input));
        }
    }
}